package com.cqc.immersivemode01;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.ButtonBarLayout;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";
    private boolean flag = false;//是否开启 沉浸式
    private boolean flag2 = false;//是否开启 沉浸式
    private View decorView;
    private Button btn;
    private Button btn2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btn = (Button) findViewById(R.id.btn);
        btn2 = (Button) findViewById(R.id.btn2);
        decorView = getWindow().getDecorView();


        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (flag) {
                    decorView.setSystemUiVisibility(View.VISIBLE);
                    flag = false;
                } else {
                    decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
                    flag = true;
                }
            }
        });


        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                View decorView = getWindow().getDecorView();
                int uiOptions = decorView.getSystemUiVisibility();
                uiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
                uiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN;
                uiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
                decorView.setSystemUiVisibility(uiOptions);
            }
        });


        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
            @Override
            public void onSystemUiVisibilityChange(int visibility) {
                Log.d(TAG,"visibility="+visibility);
                int height = decorView.getHeight();
                int measuredHeight = decorView.getMeasuredHeight();
                Log.d(TAG,"height="+height+",measuredHeight="+measuredHeight);
            }
        });

    }
}
